package com.designoutput.ui
{
	import com.designoutput.event.CardEvent;
	import com.designoutput.ui.newControls.Box;
	import com.designoutput.utils.Globals;
	
	import flash.display.Sprite;
	import flash.events.Event;

	public class FacesToolBar extends Box
	{
		private var _layersHolder:Sprite;
		private var _card:Card;
		
		override protected function initialize():void {
			super.initialize();
			
			_card = Globals.designoutputCard.card;
						
			width = 150;
			height = 300;
			
			_layersHolder = new Sprite();
			_layersHolder.x = 10;
			_layersHolder.y = 30;
			addChild(_layersHolder);
			
			setTitle("Faces");
			
			_card.addEventListener( CardEvent.CARD_TYPE_CHANGED, card_cardTypeChangedHandler, false, 0, true);
			
			update();
		}
		
		protected function card_cardTypeChangedHandler(e:Event):void {
			update();
		}
		
		private function update():void {
			while(_layersHolder.numChildren > 0)
				_layersHolder.removeChildAt(0);
			
			var currY:Number = 0;
			
			for each(var cardLayer:CardFace in _card.layers)
			{
				var layerItem:FacesToolBarItem = new FacesToolBarItem();
				layerItem.layer = cardLayer;
				layerItem.y = currY;
				_layersHolder.addChild(layerItem);
				currY += layerItem.height;
			}
		}
	}
}